package cn.iocoder.yudao.module.dr.dal.mysql.source;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.dr.controller.admin.report.vo.index.*;
import cn.iocoder.yudao.module.dr.controller.admin.source.vo.SourceCatalogWithSourceDataRespVO;
import cn.iocoder.yudao.module.dr.controller.admin.source.vo.SourcePageReqVO;
import cn.iocoder.yudao.module.dr.controller.admin.sourcecatalog.vo.SourceCatalogPageReqVO;
import cn.iocoder.yudao.module.dr.dal.dataobject.source.SourceDO;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 资源信息 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface SourceMapper extends BaseMapperX<SourceDO> {

    default PageResult<SourceDO> selectPage(SourcePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SourceDO>()
                .likeIfPresent(SourceDO::getSourceName, reqVO.getSourceName())
                .eqIfPresent(SourceDO::getSourceCode, reqVO.getSourceCode())
                .eqIfPresent(SourceDO::getSourceType, reqVO.getSourceType())
                .eqIfPresent(SourceDO::getSourceDesc, reqVO.getSourceDesc())
                .eqIfPresent(SourceDO::getFileType, reqVO.getFileType())
                .eqIfPresent(SourceDO::getFileSize, reqVO.getFileSize())
                .eqIfPresent(SourceDO::getFile, reqVO.getFile())
                .eqIfPresent(SourceDO::getSourceFrom, reqVO.getSourceFrom())
                .eqIfPresent(SourceDO::getSourceStatus, reqVO.getSourceStatus())
                .betweenIfPresent(SourceDO::getCreateTime, reqVO.getCreateTime())
                .last("ORDER BY CONVERT(INTEGER, source_code) ASC"));  // 达梦的 CONVERT 语法
    }

    default List<SourceDO> queryByIds(List<Long> list){
        return selectList(new LambdaQueryWrapperX<SourceDO>()
                .in(SourceDO::getId, list));
    };

    IPage<SourceDO> selectPendingList(Page<SourceDO> page, SourcePageReqVO pageReqVO);

    IPage<SourceDO> selectApply(Page<SourceDO> page,SourcePageReqVO pageReqVO);

    @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
    List<SourceTypeDataRespVO> countBySourceType();

    @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
    List<FileTypeDataRespVO> countByFileType();

    @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
    List<DeptUseDataRespVO> countByDeptUse();

    @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
    List<VisitDataRespVO> countByVisit();

    @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
    List<SourceTypeDataRespVO> countUseBySourceType();

    @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
    List<FileTypeDataRespVO> countUseByFileType();

    @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
    List<DeptUseDataRespVO> countUseByDept();

    @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
    List<SourceTypeDataRespVO> countVisitBySourceType();

    @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
    List<FileTypeDataRespVO> countVisitByFileType();

    @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
    List<VisitDataRespVO> countVisitByTime();

    @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
    List<VisitMothDataRespVO> countVisitByMoth();

    IPage<SourceCatalogWithSourceDataRespVO> searchSource(Page<SourceCatalogWithSourceDataRespVO> page, SourceCatalogPageReqVO pageReqVO);

    IPage<SourceCatalogWithSourceDataRespVO> selectUseApply(Page<SourceCatalogWithSourceDataRespVO> page, SourceCatalogPageReqVO pageReqVO);

    List<SourceCatalogWithSourceDataRespVO> queryListByIds(List<Long> list);
}